--package declaration
	package prims is
		function inc(x : bit_vector) return bit_vector;
		function dec(x : bit_vector) return bit_vector;
		function intval(val: bit_vector) return integer;
	end prims;
--package initialization
	package body prims is
		function inc(x: bit_vector) return bit_vector is
			variable xv: bit_vector(x'length-1 downto 0);
		begin
			xv := x;
			for i in 0 to xv'high loop
				if xv(i) = '0' then
					xv(i) := '1';
					exit;
				else xv(i) := '0';
				end if;
			end loop;
			return xv;
		end inc;
		function dec(x: bit_vector) return bit_vector is
			variable xv: bit_vector(x'length-1 downto 0);
		begin
			xv := x;
			for i in 0 to xv'high loop
				if xv(i) = '1' then
					xv(i) := '0';
					exit;
				else xv(i) := '1';
				end if;
			end loop;
			return xv;
		end dec;
		function intval(val: bit_vector) return integer is
			variable valv: bit_vector(val'length-1 downto 0);
			variable sum: integer := 0;
		begin
			valv := val;
			for n in valv'low to valv'high loop
				if valv(n) = '1' then
					sum := sum + (2**n);
				end if;
			end loop;
			return sum;
		end intval;
	end prims;
